﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class JLTVA : DocumentBase
    {
        #region-------------Properties-----------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        JLTVAData m_Data, m_DataX;
        public DataSet setUI=new DataSet();
        public DataSet dsParamaters;
        public DataRow dwABPOS;
        public INTEXDBC INTEXDBC;
        private DataRow dwUI;
        DataTable tableUI;   
        #endregion
        public JLTVA()
        {
            InitializeComponent();
            this.Name = "销售品种";
           
        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            base.SetUp(dicParamater);
            InitializeComponent();
            this.dicParamater = dicParamater;
            OracleDB = (OracleConnection)dicParamater["OracleDB"];
            proxy = (IntexReptServBLClient)dicParamater["proxy"];
            orlReadCommand = OracleDB.CreateCommand();
            orlReadCommand.Parameters.Add("OrdNum", OracleType.NVarChar).Value = "";
            m_Data = new JLTVAData();
            m_Data.OracleDB = this.OracleDB;
            m_Data.proxy = this.proxy;
            INTEXDBC = new INTEXDBC(OracleDB, proxy);
            tableUI = new DataTable("UIData");
            tableUI.Columns.Add("STAFF", typeof(string));
            tableUI.Columns.Add("COLL", typeof(string));
            tableUI.Columns.Add("ARTICLE", typeof(string));
            tableUI.Columns.Add("CUSTOMER", typeof(string));
            tableUI.Columns.Add("DESCR", typeof(string));
            
        }

        private void InitDataBinding()
        {
             
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                dwUI = tableUI.NewRow();
                InitDataBinding();
                txtSTAFF.Focus();
               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                using (new LongOperation(this, "读取符合条件的记录"))
                {
                    DataSet setResult = new DataSet();
                    setUI.Clear();
                    setUI.AcceptChanges();
                    string STAFF = txtSTAFF.Text.Trim();
                    string COLL = txtCOLL.Text.Trim();
                    string ARTICLE = txtARTICLE.Text.Trim();
                    string CUSTOMER = txtCUSTOMER.Text.Trim();
                    string DESCR = txtDESCR.Text.Trim();
                    if (STAFF == "")
                    {
                        STAFF = "AAAAAAAA";
                    }
                    if (COLL == "")
                    {
                        COLL = "AAAAA";
                    }
                    if (CUSTOMER == "")
                    {
                        CUSTOMER = "00000000";
                    }  
                    dwUI["STAFF"] = STAFF;
                    dwUI["COLL"] = COLL;
                    dwUI["ARTICLE"] = ARTICLE;
                    dwUI["CUSTOMER"] = CUSTOMER;
                    dwUI["DESCR"] = DESCR;
                    setResult = m_Data.BuildJLTVAData(dwUI);
                    setUI.Merge(setResult);
                    MasterDg.DataContext = setUI.Tables["WASTAMM"];
                }
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
                
        private void btnEXCEL_Click(object sender, RoutedEventArgs e)
        {
            m_DataX = new JLTVAData(dicParamater);
            m_DataX.exAgent._app.Visible = false;
            m_DataX.OracleDB = this.OracleDB;
            m_DataX.proxy = this.proxy;
            JLTVAReport m_rpt = new JLTVAReport(dicParamater);
            m_rpt.dsSource = setUI;
            m_rpt.PrintType = "OpenExcel";
            m_rpt.exAgent = m_DataX.exAgent;
            m_rpt.WriteExcelReport("OpenExcel");
        }

                
        private void txtART_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key != System.Windows.Input.Key.Enter) return;
            btnQuery_Click(null,null);

        }

    }
}
